package com.hang.gymmanager.controller;

import com.hang.gymmanager.Enum.ImgTypeEnum;
import com.hang.gymmanager.common.Response;
import com.hang.gymmanager.entity.PlaceEntity;
import com.hang.gymmanager.req.ReserveDetailReq;
import com.hang.gymmanager.req.ReservePlaceReq;
import com.hang.gymmanager.req.UpdatePlaceReq;
import com.hang.gymmanager.res.AbleDateRes;
import com.hang.gymmanager.res.PlaceDetailRes;
import com.hang.gymmanager.res.ReserveDetailRes;
import com.hang.gymmanager.service.PlaceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.util.List;

/**
 * 场地控制器
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/place")
@CrossOrigin
public class PlaceController {

    private final PlaceService placeService;

    /**
     * 获取所有场地
     * @return
     */
    @GetMapping("/getAll")
    public Response<List<PlaceEntity>> getAllPlaces(){
        List<PlaceEntity> list = placeService.getAllPlaces();
        return Response.success(list);
    }

    /**
     * 获取场地具体信息
     * @param placeId
     * @return
     */
    @GetMapping("/detail/{placeId}")
    public Response<PlaceDetailRes> getPlaceDetail(@PathVariable Integer placeId){
        PlaceDetailRes res = placeService.getPlaceDetail(placeId);
        return Response.success(res);
    }

    /**
     * 用户端获取场地具体信息
     * @param placeId
     * @return
     */
    @GetMapping("/user/detail/{placeId}")
    public Response<PlaceDetailRes> userPlaceDetail(@PathVariable Integer placeId){
        PlaceDetailRes res = placeService.getPlaceDetail(placeId);
        return Response.success(res);
    }

    /**
     * 更新场地信息
     * @param req
     * @return
     */
    @PostMapping("/update")
    public Response updatePlaceDetail(@RequestBody UpdatePlaceReq req){
        placeService.updatePlaceDetail(req);
        return Response.success();
    }


    /**
     * 添加或者更新场地图片
     * @param file
     * @param placeId
     * @return
     */
    @PostMapping("/uploadPic")
    public Response uploadPic(@RequestParam("file") MultipartFile file,
                              @RequestParam("placeId") Integer placeId){
        placeService.uploadPic(file,placeId);
        return Response.success();
    }


    /**
     * 获取场地可用日期
     * @param placeId
     * @return
     */
    @GetMapping("/getAbleDate/{placeId}")
    public Response<List<AbleDateRes>> getAbleDate(@PathVariable Integer placeId){
        List<AbleDateRes> ableDate =  placeService.getAbleDate(placeId);
        return Response.success(ableDate);
    }

    /**
     * 预定场地详情
     * @param req
     * @return
     */
    @PostMapping("/reserve/detail")
    public Response<ReserveDetailRes> reserveDetail(@RequestBody ReserveDetailReq req){
        ReserveDetailRes res = placeService.reserveDetail(req);
        return Response.success(res);
    }

    /**
     * 预定场地
     * @param req
     * @return
     */
    @PostMapping("/reserve")
    public Response reserve(@RequestBody ReservePlaceReq req){
        placeService.reserve(req);
        return Response.success();
    }



}
